<template>
	<!-- 月初计划 -->
	<view class="body">
		<myHeader :title="title"></myHeader>
		<view class="mt-5">
			<uni-search-bar @confirm="sreachIt()" :focus="false" v-model="search" @clear="clear"></uni-search-bar>
			<!-- 新增计划按钮 负责人可查看 -->
			<view v-if="currentRoleCode.includes('fl-leader')">
				<uni-fab :pattern="btnPattern" @fabClick="pageTo('./add')"></uni-fab>
			</view>
			<!-- 计划列表 -->
			<uni-list v-for="(item,index) in list" :key="item.id">
				<uni-list-item :title="item.name+'（'+item.score+' 求是币'+'）'" link="navigateTo" @click="pageTo('./detail',item)"
					:note="item.status==0 ? '进行中':'已完成'">
				</uni-list-item>
			</uni-list>
		</view>
	</view>
</template>	

<script>
	import myHeader from '../components/head.vue'
	import NetWorkTool from '@/api/netWorkTool'
	export default {
		data() {
			return {
				title: '悬赏任务',
				search: '',
				btnPattern: {
					buttonColor: '#e20909'
				},
				taskList: [{
					id: '1',
					title: '任务1',
					status: '待组长分配'

				}],
				// 列表请求参数
				current: 1,
				pageSize: 10,
				name: '',
				list: [],
				// 当前用户角色
				currentRoleCode: []
			}
		},
		mounted() {
			// 请求列表
			this.getList();
			this.getLoginUserRoles();
		},
		methods: {
			// 获取登录用户角色
			getLoginUserRoles() {
				let _this = this;
				uni.getStorage({
					key: 'user',
					success(e) {
						let arr = [];
						for (let item of e.data.role) {
							if (null != item.roleCode) {
								_this.currentRoleCode.push(item.roleCode)
							}
						}
					}
				})
			},
			// 请求列表
			getList() {
				// 如果是负责人
				NetWorkTool.POST('/api/reward-task/rewardList', {
					name: this.search
				}, true).then(res => {
					this.list = res;
				})
			},
			//下拉刷新
			onPullDownRefresh() {
				uni.stopPullDownRefresh();
			},
			pageTo(val, data) {
				if (undefined != data) {
					uni.navigateTo({
						url: val + "?data=" + JSON.stringify(data)
					})
				} else {
					uni.navigateTo({
						url: val
					})
				}
			},
			sreachIt() {
				uni.showToast({
					title: this.search,
					duration: 1000
				})
				this.getList();
			},
			clear() {
				this.search = ''
				this.getList()
			}
		},
		components: {
			myHeader
		},
	}
</script>

<style>
	@import url("/static/party_building/assets/style/federation.css");
</style>
